<?php

namespace Library\Models;

use \Library\Entities\Connexion;

class ConnexionManager_PDO extends ConnexionManager {

    public function checkAuth($user, $password) {
        $sql = "SELECT email, password FROM users where email='$user'";
        $requete = $this->dao->query($sql);
        $requete->setFetchMode(\PDO::FETCH_CLASS | \PDO::FETCH_PROPS_LATE, '\Library\Entities\Connexion');

        foreach ($requete->fetchall() as $row) {
            $mail = $row->mail();
            $pwd = $row->mdp();
            if ($mail === $user) {
                if ($pwd === $password) {
                    $requete->closeCursor();
                    return true;
                } else {
                    $requete->closeCursor();
                    return false;
                }
            } else {
                $requete->closeCursor();
                return false;
            }
        }
    }

}

?>